const markPointBg = require("../assets/images/tooptip-bg_03.png");

console.log(markPointBg);

export default function getChartOption(data = []) {
  // data = [
  //   {
  //     date: "2018-07-24",
  //     annual_proift: "1.00070000"
  //   },
  //   {
  //     date: "2018-07-25",
  //     annual_proift: "1.00570000"
  //   },
  //   {
  //     date: "2018-07-26",
  //     annual_proift: "0.98885000"
  //   },
  //   {
  //     date: "2018-07-27",
  //     annual_proift: "1.00885000"
  //   },
  //   {
  //     date: "2018-07-28",
  //     annual_proift: "1.28885000"
  //   },
  //   {
  //     date: "2018-07-29",
  //     annual_proift: "1.08885000"
  //   },
  //   {
  //     date: "2018-07-30",
  //     annual_proift: "1.00000000"
  //   }
  // ];

  let xAxisData = [],
    seriesData = [],
    maxX = 0,
    maxY = 0,
    indexX = 0;
  let i = 0;
  for (i = 0; i < data.length; i++) {
    xAxisData.push(data[i].profit_date.substr(5));
    seriesData.push(parseFloat(data[i].daily_profit).toFixed(2));
    // if (maxY <= data[i].annual_proift) {
    maxX = data[i].profit_date;
    maxY = Number(data[i].daily_profit).toFixed(2);
    indexX = i;
    // }
  }

  return {
    tooltip: {
      trigger: "axis"
    },
    title: {
      z: 0,
      padding: 20,
      textStyle: {
        fontSize: 14
      },
      text: "七天日收益率(%)"
    },
    xAxis: {
      type: "category",
      boundaryGap: false,
      data: xAxisData,
      axisLabel: {
        interval: 0
      }
    },
    yAxis: {
      type: "value"
    },
    series: [
      {
        z: 99,
        name: "收益率",
        data: seriesData,
        type: "line",
        symbol: "none",
        itemStyle: {
          normal: {
            color: "#faab5e"
          }
        },
        areaStyle: {
          normal: {
            color: "#f8e8d8"
          }
        },
        markPoint: {
          z: 99,
          // symbol: "image://" + require("../assets/images/tooptip-bg_03.png"),
          // symbolSize: [80, 50],
          // symbolOffset: ["-50%", "-50%"],
          label: {
            formatter: [`{a|${maxY}}`, `{b|${maxX}}`].join("\n"),
            rich: {
              a: {
                padding: [0, 0, 0, 0],
                fontSize: 16,
                color: "#fff",
                textAlign: "center"
              },
              b: {
                color: "#fff",
                padding: [0, 0, 0, 0]
              }
            },
            verticalAlign: "middle",
            padding: [-10, 0, 0, 0]
          },
          data: [
            {
              name: "最大值",
              value: `${maxY} \n ${maxX}`,
              xAxis: indexX,
              yAxis: maxY
            }
          ]
        },
        smooth: true
      }
    ]
  };
}
